--- translates its input to a slightly more verbose form

-- A small joke from 𝕴𝖓𝖌𝖔 𝖂𝖊𝖈𝖍𝖘𝖚𝖓𝖌

module examples.UnicodeChars where

pure native chrname java.lang.Character.getName :: Int -> String

--- print a table of interesting unicode characters
main [] = do
    sequence_ 
        . zipWith ($) (cycle [print, println]) 
        . map nice 
        . codepoints 
        $ interesting
    println ""

--- print a description of the arguments
main args = sequence_
        . zipWith ($) (cycle [print, println]) 
        . map nice 
        . codepoints
        . joined " "
        $ args

--- ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
interesting = "∀∃√∛∜∞𝕬𝖆𝕭𝖇𝕮𝖈𝕯𝖉𝕰𝖊𝕱𝖋𝕲𝖌𝕳𝖍𝕴𝖎𝕵𝖏𝕶𝖐𝕷𝖑𝕸𝖒𝕹𝖓𝕺𝖔𝕻𝖕𝕼𝖖𝕽𝖗𝕾𝖘𝕿𝖙𝖀𝖚𝖁𝖛𝖂𝖜𝖃𝖝𝖄𝖞𝖅𝖟∷←↑→↓↔⇒░" 

codepoints s = cps 0 (CharSequence.fromString s)

cps :: Int -> CharSequence -> [Int]
cps !n !str
    | n >= str.length = []
    | n+1 < str.length, c.isSurrogatePair (str.charAt (n+1))
                      = str.codePointAt n !: recurse 2
    | otherwise = ord c !: recurse 1
    where 
        c = str.charAt n
        recurse k = cps (n+k) str

nice i = String.format "%s  U+%05x  %-40.40s" s i (chrname i) :: String
    where
        s | Char.isSupplementaryCodePoint i 
          = packed [Char.highSurrogate i, Char.lowSurrogate i]
          | otherwise = ctos (chr i)

